package com.qf.test;

import com.qf.entity.User;
import com.qf.factory.HashMapFactory;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Spring入门操作，由Spring工厂帮我创建对象，
 */
public class Demo1 {

    @Test
    public void test(){
        //1. 加载配置文件，并获取到Spring工厂对象。(Spring工厂构建的对象默认是单例的)
        ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");

        //2. 向工厂要user对象，（标识就是user）
        User user = (User) ac.getBean("user");

        //3. 输出user
        System.out.println(user);

        //4. 关闭工厂
        ac.close();
    }

    @Test
    public void factory(){
        ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");

        HashMapFactory map = ac.getBean(HashMapFactory.class);

        System.out.println(map);
    }



}
